(function() {
  var mongoose, schema;

  mongoose = require('mongoose');
  schema = mongoose.Schema({
  username: {
    type: String,
    match: /^[a-zA-Z0-9_\.]{4,16}$/
  }
  , fullname: String
  , password: String
});
 
  schema.methods.login = function(cb) {
    return cb();
  };
 
  schema.methods.logout = function(cb) {
    return cb();
  };
 
  schema.methods.register = function(cb) {
    var me;
    me = this;
    return db.user.findOne({
      username: this.username
    }, function(error, data) {
      if (error) {
        return cb(error, null);
      }
      else if (data) {
        return cb(new mongoose.Error('User account existed'), null);
      } 
      else {
        return me.save(cb);
      }
    });
  };
// checking if password is valid
  schema.methods.validPassword = function(password) {
      return this.password == password;
  };

 
  module.exports = schema;
 
}).call(this);